import moment from 'moment'

export function renderTime(time) {
    const nowStr = new Date()
    const nowMoment = moment(nowStr)
    const localStr = time ? new Date(time) : nowStr
    const localMoment = moment(localStr)
    const localFormat = localMoment.format('MM-DD hh:mm A')
    return localFormat
}
/**
 * 取值函数，避免出现undefined后再点出现的error
 * object 数据源
 * path 取值的path
 * defaultValue 默认值
 * */
export const deepGet = (object, path, defaultValue) => {
    const res = (!Array.isArray(path) ? path.replace(/\[/g, '.').replace(/]/g, '').split('.') : path)
        .reduce((o, k) => (o || {})[k], object)
    return (res !== undefined && res !== null) ? res : defaultValue
}